package com.drug.mingkang.controller;
import com.drug.mingkang.mapper.HqMarketMapper;
import com.drug.mingkang.mapper.ImmPurchaseMapper;
import com.drug.mingkang.mapper.OrderReturnApplyMapper;
import com.drug.mingkang.model.*;
import com.drug.mingkang.model.vo.AuditRecordVo;
import com.drug.mingkang.model.vo.ImmPurchaseVo;
import com.drug.mingkang.model.vo.PurchaseorderVo;
import com.drug.mingkang.model.vo.PurchasereviewVo;
import com.drug.mingkang.permission.model.PerUsers;
import com.drug.mingkang.service.*;
import com.drug.mingkang.utils.AuditStatus;
import com.drug.mingkang.utils.ResponseMessage;
import com.drug.mingkang.utils.Tools;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 审核记录表(AuditRecord)表控制层
 *
 * @author wenchangjian
 * @since 2020-08-11 12:00:12
 */
@RestController
@RequestMapping("auditRecord")
public class AuditRecordController {
    /**
     * 审核服务对象
     */
    @Resource
    private AuditRecordService auditRecordService;

    /**
     * 总公司原材料服务对象
     */
    @Resource
    private HqPurchaseorderService hqPurchaseorderService;

    /**
     * 总公司药品服务对象
     */
    @Resource
    private HqDrugService hqDrugService;

    /**
     * 分公司财务服务对象
     */
    @Resource
    private ImmFinanceService immFinanceService;

    /**
     * 采购单服务对象
     */
    @Resource
    private ImmPurchaseService immPurchaseService;

    /**
     * 生产服务对象
     */
    @Resource
    private HqPlanService hqPlanService;

    /**
     * 工具类
     */
    @Resource
    private Tools tools;
    /**
     * 分公司订单
     */
    @Resource
    private ImmPurchaseMapper immPurchaseMapper;
    /**
     * 总公司销售订单
     */
    @Resource
    private HqMarketMapper hqMarketMapper;
    /**
     * 退货订单
     */
    @Resource
    private OrderReturnApplyMapper orderReturnApplyMapper;

    @Resource
    private ImmSellService immSellService;
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne/{id}")
    public AuditRecord selectOne(@PathVariable("id") String id) {
        return this.auditRecordService.queryById(id);
    }

    /**
     * 原材料审核表
     * @author 依旧
     * @return 列表
     */
    @PostMapping("rawMaterialShowAll")
    public Map<String,Object> rawMaterialShowAll(PurchasereviewVo purchasereviewVo){
        List<HqReview> list = auditRecordService.rawMaterialShowAll(purchasereviewVo);
        int count=auditRecordService.selectrawMaterialCount(purchasereviewVo);
        return tools.limit(list,count);
    }

    /**
     * 根据业务id查询所有审核记录
     * @param auditRecordVo    实例对象
     * @author Mr.wang
     * @return
     */
    @ApiOperation(value = "根据业务id查询所有审核记录", notes = "输入业务id", httpMethod = "POST", response = Map.class)
    @ResponseBody
    @PostMapping("/showList")
    public Map<String, Object> showList(AuditRecordVo auditRecordVo){
        return auditRecordService.queryAllByLimit(auditRecordVo);
    }


    /**
     * 修改原材料采购状态(总经理审核  财务审核)
     * @param purchaseorderVo 原材料采购管理Vo
     * @return
     */
    @PostMapping("updateRawMaterialIsva")
    public ResponseMessage updateRawMaterialIsva(PurchaseorderVo purchaseorderVo, AuditRecord auditRecord, HttpSession session){
        return hqPurchaseorderService.updateIsva(purchaseorderVo,auditRecord,session);
    }


    /**
     * 采购订单审核 修改审核状态
     * @param immPurchaseVo Vo
     * @return
     */
    @PostMapping("updatePurchaseIsva")
    public ResponseMessage updatePurchaseIsva(ImmPurchaseVo immPurchaseVo, AuditRecord auditRecord,HttpSession session){
        return immPurchaseService.updateStatus(immPurchaseVo,auditRecord,session);
    }

    /**
     * 修改退货财务状态
     * @param immPurchaseVo Vo
     * @author Mr.wang
     * @return
     */
    @PostMapping("updateFinanceIsvaReturn")
    public ResponseMessage updateFinanceIsvaReturn(ImmPurchaseVo immPurchaseVo, AuditRecord auditRecord,HttpSession session){
        return auditRecordService.updateFinanceIsvaReturn(immPurchaseVo,auditRecord,session);
    }


    /**
     * 原材料审核状态查询
     */
    @ApiOperation(value = "原材料审核状态查询", notes = "原材料审核状态查询", httpMethod = "POST", response = Map.class)
    @ResponseBody
    @PostMapping("/RawMaterialShowList")
    public Map<String, Object> showList(PurchaseorderVo purchaseorderVo){
        return auditRecordService.queryAllRawMaterialByLimit(purchaseorderVo);
    }

    /**
     * 修改药品状态
     * @param hqDrug 药品Bean
     * @param auditRecord 审核Bean
     * @param session 当前会话
     * @return
     */
    @PostMapping("updateDrugIsva")
    public ResponseMessage updateDrugIsva(HqDrug hqDrug, AuditRecord auditRecord, HttpSession session){
        return hqDrugService.updateIsva(hqDrug,auditRecord,session);
    }

    /**
     * 生产订单审核 修改审核状态
     * @param hqPlan 生产计划Bean
     * @return
     */
    @PostMapping("updateProductionIsva")
    public ResponseMessage updateProductionIsva(HqPlan hqPlan, AuditRecord auditRecord, HttpSession session){
        return hqPlanService.updateStatus(hqPlan,auditRecord,session);
    }

    /**
     * 分公司财务订单审核 修改审核状态
     * @param immPurchaseVo 分公司采购单Vo
     * @return
     */
    @PostMapping("updateFinanceIsva")
    public ResponseMessage updateFinanceIsva(ImmPurchaseVo immPurchaseVo, AuditRecord auditRecord, HttpSession session){
        return immFinanceService.updateStatus(immPurchaseVo,auditRecord,session);
    }


    /**
     * 分公司批发审核
     * @param immSell 分公司批发
     * @param auditRecord 审核表
     * @param session 当前会话
     * @return
     */
    @PostMapping("updateWholesaleAudit")
    public ResponseMessage updateWholesaleAudit(ImmSell immSell, AuditRecord auditRecord, HttpSession session){
        return immSellService.updateWholesaleIsva(immSell,auditRecord,session);
    }


    /**
     * 根据总公司销售 状态查询
     */
    @ApiOperation(value = "根据总公司销售 状态查询", notes = "根据总公司销售 状态查询", httpMethod = "POST", response = Map.class)
    @ResponseBody
    @PostMapping("/showSellAuditList")
    public Map<String, Object> showSellAuditList(ImmPurchaseVo immPurchaseVo,HttpSession session){
        return immPurchaseService.queryAllByLimit(immPurchaseVo);
    }
}